<%--
  Created by IntelliJ IDEA.
  User: SoGi
  Date: 2018-11-16
  Time: 14:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <script>
        function searcha() {
            var opts = $("#shangpintb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var sname = $("#sname").val() ;
            $.post("${pageContext.request.contextPath}/shangpin/querySearch",{'sname':sname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#shangpintb").bootstrapTable('load',data) ;
            })
        }
        $(function () {
            $("#shangpintb").bootstrapTable({
                url:'${pageContext.request.contextPath}/shangpin/querySearch',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
                // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        sname:$("#sname").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'sid',
                        title:'商品编号'
                    },
                    {
                        field:'sname',
                        title:'商品姓名'
                    },
                    {
                        field:'lid',
                        title:'商品类别',
                        formatter:function (a,b,c) {
                            if (b.lid==1){
                                return "白酒类" ;
                            }
                            if (b.lid==2){
                                return "饮料类" ;
                            }
                            if (b.lid==3){
                                return "水果类" ;
                            }
                            if (b.lid==4){
                                return "食品类" ;
                            }
                        }
                    },
                    {
                        field:'sguige',
                        title:'商品规格'
                    },

                    {
                        field:'sjiage',
                        title:'商品价格'
                    },
                    {
                        field:'did',
                        title:'商品单位',
                        formatter:function (a2,b2,c2) {
                            if (b2.did==1){
                                return "斤" ;
                            }
                            if (b2.did==2){
                                return "瓶" ;
                            }
                            if (b2.did==3){
                                return "盒" ;
                            }
                            if (b2.did==4){
                                return "袋" ;
                            }
                        }
                    },
                    {
                        field:'skucun',
                        title:'商品库存'
                    },
                    {
                        field:'cid',
                        title:'商品仓库',
                        formatter (value, row, index, field) {
                            if (row.cid == 1) {
                                return "主仓库";
                            } else if (row.cid == 2) {
                                return "水果库";
                            } else if (row.cid == 3) {
                                return "酒水库";
                            } else if (row.cid == 4) {
                                return "饮料库";
                            }
                        }
                    },
                    {
                        field:'time',
                        title:'商品日期'
                    },
                    {
                        field:'dqtime',
                        title:'到期日期'
                    },
                ]
            }) ;
        }) ;

        function searcha() {
            var opts = $("#shangpintb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var sname = $("#sname").val() ;
            $.post("${pageContext.request.contextPath}/shangpin/querySearch",{'sname':sname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#shangpintb").bootstrapTable('load',data) ;
            })
        }
    </script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">商品列表</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-12">
                <form  class="form-inline pull-right">
                    <input id="sname" type="text" class="form-control">

                    <input onclick="searcha()"  class="btn btn-primary" type="button" value="提交">
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="shangpintb"></table>
            </div>
        </div>

    </div>
</div>

</body>
</html>
